package org.newtech.examples.jpa;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Table;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Transient;

@Entity
@Table(name="PRODUCT")
public class Product{

    @Transient
    @PersistenceContext(unitName = "jpa")
    private static EntityManager entityManager;

    @Id
    @Column(name="PRODUCT_CODE")
    private String productCode;

    public static Product find(String productCode)
    {
        return entityManager.find(Product.class, productCode);
    }

    @Column(name="PRODUCT_NAME")
    private String productName;

    public String getProductCode() {
        return productCode;
    }
    public void setProductCode(String code) {
        productCode = code;
    }
    public String getProductName() {
        return productName;
    }
    public static EntityManager getEntityManager()
    {
        return entityManager;
    }

    public static void setEntityManager(EntityManager entityManager)
    {
        Product.entityManager = entityManager;
    }

}

